<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  Module: TableData::Detection
  
    &mdash; Documentation by YARD 0.8.7.3
  
</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  hasFrames = window.top.frames.main ? true : false;
  relpath = '../';
  framesUrl = "../frames.html#!" + escape(window.location.href);
</script>


  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <div id="header">
      <div id="menu">
  
    <a href="../_index.html">Index (D)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../TableData.html" title="TableData (module)">TableData</a></span></span>
     &raquo; 
    <span class="title">Detection</span>
  

  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../class_list.html">
      Class List
    </a>
  
    <a class="full_list_link" id="method_list_link"
        href="../method_list.html">
      Method List
    </a>
  
    <a class="full_list_link" id="file_list_link"
        href="../file_list.html">
      File List
    </a>
  
</div>
      <div class="clear"></div>
    </div>

    <iframe id="search_frame"></iframe>

    <div id="content"><h1>Module: TableData::Detection
  
  
  
</h1>

<dl class="box">
  
  
    
  
    
  
  
  
    <dt class="r1 last">Defined in:</dt>
    <dd class="r1 last">lib/tabledata/detection.rb</dd>
  
</dl>
<div class="clear"></div>


  <h2>Constant Summary</h2>
  
    <dl class="constants">
      
        <dt id="UnlikelyCharsWin1252-constant" class="">UnlikelyCharsWin1252 =
          
        </dt>
        <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD</span><span class='tstring_end'>&quot;</span></span> \
<span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB</span><span class='tstring_end'>&quot;</span></span> \
<span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\xBC\xBD\xBE\xBF\xD7\xF7</span><span class='tstring_end'>&quot;</span></span></pre></dd>
      
        <dt id="UnlikelyCharsIso8859_1-constant" class="">UnlikelyCharsIso8859_1 =
          
        </dt>
        <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span></pre></dd>
      
        <dt id="UnlikelyCharsMacRoman-constant" class="">UnlikelyCharsMacRoman =
          
        </dt>
        <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_end'>&quot;</span></span></pre></dd>
      
        <dt id="UmlautsMac-constant" class="">UmlautsMac =
          
        </dt>
        <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>äöü</span><span class='tstring_end'>&quot;</span></span><span class='period'>.</span><span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>MacRoman</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>BINARY</span><span class='rparen'>)</span></pre></dd>
      
        <dt id="UmlautsWin-constant" class="">UmlautsWin =
          
        </dt>
        <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>äöü</span><span class='tstring_end'>&quot;</span></span><span class='period'>.</span><span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>Windows_1252</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>BINARY</span><span class='rparen'>)</span></pre></dd>
      
        <dt id="DiacritsMac-constant" class="">DiacritsMac =
          
        </dt>
        <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>âàéèô</span><span class='tstring_end'>&quot;</span></span><span class='period'>.</span><span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>MacRoman</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>BINARY</span><span class='rparen'>)</span></pre></dd>
      
        <dt id="DiacritsWin-constant" class="">DiacritsWin =
          
        </dt>
        <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>âàéèô</span><span class='tstring_end'>&quot;</span></span><span class='period'>.</span><span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>Windows_1252</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>BINARY</span><span class='rparen'>)</span></pre></dd>
      
    </dl>
  







  
    <h2>
      Class Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#file_type_from_path-class_method" title="file_type_from_path (class method)">+ (Object) <strong>file_type_from_path</strong>(path) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#force_guessed_encoding%21-class_method" title="force_guessed_encoding! (class method)">+ (Object) <strong>force_guessed_encoding!</strong>(string) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#guess_csv_delimiter-class_method" title="guess_csv_delimiter (class method)">+ (Object) <strong>guess_csv_delimiter</strong>(csv, out_of = [&#39;,&#39;,&#39;;&#39;]) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#guess_encoding-class_method" title="guess_encoding (class method)">+ (Object) <strong>guess_encoding</strong>(string) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'></div></span>
  
</li>

      
    </ul>
  



  <div id="class_method_details" class="method_details_list">
    <h2>Class Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="file_type_from_path-class_method">
  
    + (<tt>Object</tt>) <strong>file_type_from_path</strong>(path) 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


67
68
69
70
71
72
73
74</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/tabledata/detection.rb', line 67</span>

<span class='kw'>def</span> <span class='id identifier rubyid_file_type_from_path'>file_type_from_path</span><span class='lparen'>(</span><span class='id identifier rubyid_path'>path</span><span class='rparen'>)</span>
  <span class='kw'>case</span> <span class='id identifier rubyid_path'>path</span>
    <span class='kw'>when</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\.csv$</span><span class='regexp_end'>/</span></span> <span class='kw'>then</span> <span class='symbol'>:csv</span>
    <span class='kw'>when</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\.xls$</span><span class='regexp_end'>/</span></span> <span class='kw'>then</span> <span class='symbol'>:xls</span>
    <span class='kw'>when</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\.xlsx$</span><span class='regexp_end'>/</span></span> <span class='kw'>then</span> <span class='symbol'>:xlsx</span>
    <span class='kw'>else</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>InvalidFileType</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Unknown file format for path </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_path'>path</span><span class='period'>.</span><span class='id identifier rubyid_inspect'>inspect</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
  <span class='kw'>end</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="force_guessed_encoding!-class_method">
  
    + (<tt>Object</tt>) <strong>force_guessed_encoding!</strong>(string) 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/tabledata/detection.rb', line 25</span>

<span class='kw'>def</span> <span class='id identifier rubyid_force_guessed_encoding!'>force_guessed_encoding!</span><span class='lparen'>(</span><span class='id identifier rubyid_string'>string</span><span class='rparen'>)</span>
  <span class='kw'>return</span> <span class='id identifier rubyid_string'>string</span> <span class='kw'>if</span> <span class='id identifier rubyid_string'>string</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>UTF_8</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_valid_encoding?'>valid_encoding?</span>
  <span class='id identifier rubyid_string'>string</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>BINARY</span><span class='rparen'>)</span>

  <span class='comment'># check for non-mapped codepoints
</span>  <span class='id identifier rubyid_possible_encodings'>possible_encodings</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>Windows_1252</span><span class='comma'>,</span> <span class='const'>Encoding</span><span class='op'>::</span><span class='const'>ISO8859_15</span><span class='comma'>,</span> <span class='const'>Encoding</span><span class='op'>::</span><span class='const'>MacRoman</span><span class='rbracket'>]</span>
  <span class='id identifier rubyid_possible_encodings'>possible_encodings</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>ISO8859_15</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_string'>string</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>[\x80-\x9f]</span><span class='regexp_end'>/n</span></span>
  <span class='id identifier rubyid_possible_encodings'>possible_encodings</span><span class='period'>.</span><span class='id identifier rubyid_delete'>delete</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>Windows_1252</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_string'>string</span> <span class='op'>=~</span> <span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>[\x81\x8D\x8F\x90\x9D]</span><span class='regexp_end'>/n</span></span>
  <span class='kw'>return</span> <span class='id identifier rubyid_string'>string</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='id identifier rubyid_possible_encodings'>possible_encodings</span><span class='period'>.</span><span class='id identifier rubyid_first'>first</span><span class='rparen'>)</span> <span class='kw'>if</span> <span class='id identifier rubyid_possible_encodings'>possible_encodings</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'>==</span> <span class='int'>1</span>

  <span class='comment'># # check for occurrences of characters with weighted expectancy
</span>  <span class='comment'># # e.g. a &quot;§&quot; is quite unlikely
</span>  <span class='comment'># win = string[0,10_000].count(UnlikelyCharsWin1252)
</span>  <span class='comment'># iso = string[0,10_000].count(UnlikelyCharsIso8859_1)
</span>  <span class='comment'># mac = string[0,10_000].count(UnlikelyCharsMacRoman)
</span>
  <span class='comment'># Check occurrences of äöü
</span>  <span class='kw'>case</span> <span class='id identifier rubyid_string'>string</span><span class='lbracket'>[</span><span class='int'>0</span><span class='comma'>,</span><span class='int'>10_000</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_count'>count</span><span class='lparen'>(</span><span class='const'>UmlautsMac</span><span class='rparen'>)</span> <span class='op'>&lt;=&gt;</span> <span class='id identifier rubyid_string'>string</span><span class='lbracket'>[</span><span class='int'>0</span><span class='comma'>,</span><span class='int'>10_000</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_count'>count</span><span class='lparen'>(</span><span class='const'>UmlautsWin</span><span class='rparen'>)</span>
    <span class='kw'>when</span> <span class='op'>-</span><span class='int'>1</span> <span class='kw'>then</span> <span class='kw'>return</span> <span class='id identifier rubyid_string'>string</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>Windows_1252</span><span class='rparen'>)</span>
    <span class='kw'>when</span>  <span class='int'>1</span> <span class='kw'>then</span> <span class='kw'>return</span> <span class='id identifier rubyid_string'>string</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>MacRoman</span><span class='rparen'>)</span>
  <span class='kw'>end</span>

  <span class='comment'># Check occurrences of âàéèô
</span>  <span class='kw'>case</span> <span class='id identifier rubyid_string'>string</span><span class='lbracket'>[</span><span class='int'>0</span><span class='comma'>,</span><span class='int'>10_000</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_count'>count</span><span class='lparen'>(</span><span class='const'>DiacritsMac</span><span class='rparen'>)</span> <span class='op'>&lt;=&gt;</span> <span class='id identifier rubyid_string'>string</span><span class='lbracket'>[</span><span class='int'>0</span><span class='comma'>,</span><span class='int'>10_000</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_count'>count</span><span class='lparen'>(</span><span class='const'>DiacritsWin</span><span class='rparen'>)</span>
    <span class='kw'>when</span> <span class='op'>-</span><span class='int'>1</span> <span class='kw'>then</span> <span class='kw'>return</span> <span class='id identifier rubyid_string'>string</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>Windows_1252</span><span class='rparen'>)</span>
    <span class='kw'>when</span>  <span class='int'>1</span> <span class='kw'>then</span> <span class='kw'>return</span> <span class='id identifier rubyid_string'>string</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>MacRoman</span><span class='rparen'>)</span>
  <span class='kw'>end</span>

  <span class='comment'># Bias for Windows_1252
</span>  <span class='id identifier rubyid_string'>string</span><span class='period'>.</span><span class='id identifier rubyid_force_encoding'>force_encoding</span><span class='lparen'>(</span><span class='const'>Encoding</span><span class='op'>::</span><span class='const'>Windows_1252</span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="guess_csv_delimiter-class_method">
  
    + (<tt>Object</tt>) <strong>guess_csv_delimiter</strong>(csv, out_of = [&#39;,&#39;,&#39;;&#39;]) 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


61
62
63
64
65</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/tabledata/detection.rb', line 61</span>

<span class='kw'>def</span> <span class='id identifier rubyid_guess_csv_delimiter'>guess_csv_delimiter</span><span class='lparen'>(</span><span class='id identifier rubyid_csv'>csv</span><span class='comma'>,</span> <span class='id identifier rubyid_out_of'>out_of</span><span class='op'>=</span><span class='lbracket'>[</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>,</span><span class='tstring_end'>&#39;</span></span><span class='comma'>,</span><span class='tstring'><span class='tstring_beg'>&#39;</span><span class='tstring_content'>;</span><span class='tstring_end'>&#39;</span></span><span class='rbracket'>]</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_out_of'>out_of</span> <span class='op'>=</span> <span class='id identifier rubyid_out_of'>out_of</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_delimiter'>delimiter</span><span class='op'>|</span> <span class='id identifier rubyid_delimiter'>delimiter</span><span class='period'>.</span><span class='id identifier rubyid_encode'>encode</span><span class='lparen'>(</span><span class='id identifier rubyid_csv'>csv</span><span class='period'>.</span><span class='id identifier rubyid_encoding'>encoding</span><span class='rparen'>)</span> <span class='rbrace'>}</span>

  <span class='id identifier rubyid_out_of'>out_of</span><span class='period'>.</span><span class='id identifier rubyid_max_by'>max_by</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_delimiter'>delimiter</span><span class='op'>|</span> <span class='id identifier rubyid_csv'>csv</span><span class='lbracket'>[</span><span class='int'>0</span><span class='comma'>,</span> <span class='int'>10_000</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_count'>count</span><span class='lparen'>(</span><span class='id identifier rubyid_delimiter'>delimiter</span><span class='rparen'>)</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="guess_encoding-class_method">
  
    + (<tt>Object</tt>) <strong>guess_encoding</strong>(string) 
  

  

  
</h3><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


57
58
59</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'lib/tabledata/detection.rb', line 57</span>

<span class='kw'>def</span> <span class='id identifier rubyid_guess_encoding'>guess_encoding</span><span class='lparen'>(</span><span class='id identifier rubyid_string'>string</span><span class='rparen'>)</span>
  <span class='id identifier rubyid_force_guessed_encoding!'>force_guessed_encoding!</span><span class='lparen'>(</span><span class='id identifier rubyid_string'>string</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_encoding'>encoding</span>
<span class='kw'>end</span></pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

    <div id="footer">
  Generated on Sun Feb 23 13:33:18 2014 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.8.7.3 (ruby-2.1.0).
</div>

  </body>
</html>